package com.snap.vseries.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.snap.vseries.R;
import com.snap.vseries.adapter.ResultTableListAdapter;
import com.snap.vseries.base.BaseFragment;
import com.snap.vseries.bean.ExpInfo;
import com.snap.vseries.ui.widget.RecyclerViewCornerRadius;

import butterknife.BindView;
import me.jessyan.autosize.utils.AutoSizeUtils;

/**
 * 实验结果：报告-ct
 */
@SuppressLint("ValidFragment")
public class ResultTableListFragment extends BaseFragment {

    @BindView(R.id.rec)
    RecyclerView rec;
    private ExpInfo experimentInfo;
    private ResultTableListAdapter adapter;

    public void setExperimentInfo(ExpInfo experimentInfo) {
        this.experimentInfo = experimentInfo;
        if (adapter != null && experimentInfo.getHoleInfo().getChannelData() != null) {
            initData();
        }
    }

    public void notifyAnalyzeFinished() {
        if (adapter != null) {
            initData();
        }
    }

    @Override
    protected int layoutResId() {
        return R.layout.fragment_result_table_list;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        initViews();
        if (experimentInfo != null && experimentInfo.getHoleInfo().getChannelData() != null) {
            initData();
        }
    }

    private void initViews() {
        rec.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new ResultTableListAdapter();
        rec.setAdapter(adapter);
        //加圆角
        RecyclerViewCornerRadius radiusItemDecoration = new RecyclerViewCornerRadius(rec);
        radiusItemDecoration.setCornerRadius(AutoSizeUtils.dp2px(getContext(), 4));
        rec.addItemDecoration(radiusItemDecoration);
    }

    private void initData() {
        adapter.initData(experimentInfo);
    }

    public void changeAnalyzeType() {
        if (adapter != null)
            adapter.changeAnalyzeType();
    }
}
